package com.cn.spring.web.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.cn.spring.web.dao.UserDao;
import com.cn.spring.web.model.TUser;

@Component
public class UserDaoImpl implements UserDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Autowired
	private HibernateTemplate hibernateTemplate;

	public void saveUser(TUser userr) {
		hibernateTemplate.save(userr);
	}

	public void deleteUser(Long id) {
		String sql = " delete  from tuser where id = "+ id;
		jdbcTemplate.execute(sql);
	}

	public void updateUser(TUser user) {
		hibernateTemplate.update(user);
	}

	public TUser findUser(Long id) {
		String sql = " from TUser where id = ?";
		return (TUser)hibernateTemplate.find(sql, id).get(0);
	}
}
